package com.geuso.xingdutch.words;

import java.util.ArrayList;
import java.util.Collections;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ListView;

import com.geuso.xingdutch.R;
import com.geuso.xingdutch.activity.DefaultActivity;

public class WordsActivity extends DefaultActivity {
	
	private ListView word_list;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        
		setContentView(R.layout.word_overview);
		word_list = (ListView) findViewById(R.id.word_list);
		word_list.setAdapter(new WordsListAdapter(this, 
				R.layout.word_item, WordsData.words));

		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    // Inflate the menu items for use in the action bar
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.words_overview_actions, menu);
	    return super.onCreateOptionsMenu(menu);
	}

	@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.action_randomize:
        	refreshList();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
	
	
	private void refreshList(){
		ArrayList<Word> new_list = WordsData.getWordsClone();
		Collections.shuffle(new_list);
		word_list.setAdapter(new WordsListAdapter(this, R.layout.word_item, new_list));
	}

}
